package huawei;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[][] mat = new int[n][2];
        int end = 0;
        int start = -1;
        for(int i=0;i<n;i++){
            mat[i][0] = in.nextInt();
            mat[i][1] = in.nextInt();
            start = start == -1? mat[i][0]:Math.min(start,mat[i][1]);
            end = Math.max(end,mat[i][1]);
        }
        int[] cost = new int[end + 1];

        for(int i = start;i<=end;i++){
            cost[i] = 1;
        }

        for(int i = 0;i<n;i++){
            int a = mat[i][0];
            int b = mat[i][1];

            for(int j = a;j<=b;j++){
                if(cost[j] == 1) cost[j] = 3;
                else if(cost[j] == 3) cost[j] = 4;
            }
        }

        long res = 0;
        for (int i : cost) {
            res+=i;
        }

        for(int i = start;i<=n;i++){
            res+=cost[i];
        }
        System.out.println(res);
    }
}
